package com.csu.letaobackend.controllerM;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.csu.letaobackend.bean.Shopcoupon;
import com.csu.letaobackend.bean.Swiperitem;
import com.csu.letaobackend.commom.CommonResponse;
import com.csu.letaobackend.persistence.SwiperitemDao;
import com.csu.letaobackend.serviceM.SwiperitemMService;
import com.csu.letaobackend.vo.SwiperitemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@CrossOrigin
@RequestMapping("/admin/swiperitem")
public class SwiperitemMController {

      @Autowired
      SwiperitemMService swiperitemMService;

      @GetMapping("/swiperitems/query/pages/{pagesize}/{pageid}")
      @ResponseBody
      CommonResponse<IPage<SwiperitemVO>> getAllSwiperitems(@PathVariable int pageid, @PathVariable int pagesize) {

            return swiperitemMService.getAllSwiperitems(pageid, pagesize);
      }

      @GetMapping("/{slogan}/{shopname}/swiperitems/query/pages/{pagesize}/{pageid}")
      @ResponseBody
      CommonResponse<IPage<SwiperitemVO>> searchSwiperitem(@PathVariable String slogan,
                                                           @PathVariable String shopname, @PathVariable int pageid, @PathVariable int pagesize) {
            return swiperitemMService.searchSwiperitem(slogan, shopname, pageid, pagesize);
      }


      @PostMapping("")
      @ResponseBody
      CommonResponse addCoupon(@RequestBody Swiperitem swiperitem) {

            return swiperitemMService.addSwiperitem(swiperitem);
      }

      @DeleteMapping("/{itemid}")
      @ResponseBody
      CommonResponse deleteCoupon(@PathVariable  int itemid) {
            return swiperitemMService.deleteSwiperitem(itemid);
      }

      @PutMapping("/{itemid}")
      @ResponseBody
      CommonResponse updateCoupon(@RequestBody Swiperitem swiperitem,@PathVariable  int itemid) {
            swiperitem.setItemid(itemid);
            return swiperitemMService.updateSwiperitem(swiperitem);
      }
}
